from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Music


class PreTest_RK3568_Multimedia_Music_0200(TestCase, Music):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.点击音乐应用
    # 2.点击播放按钮
    # 3.点击上一首切换按钮
    # 4.点击下一首切换按钮
    # 预期结果：
    # 1.正常进入音乐应用内
    # 2.音乐正常播放且有声音
    # 3.正常切换到上一首音乐并流畅播放
    # 4.正常切换到下一首音乐并流畅播放

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：点击音乐应用')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        Step('预期结果1.正常进入音乐应用内')
        CommonOH.wait(self.Phone1, 2)
        try:
            CommonOH.touchByText(self.Phone1, '允许')
        except:
            CommonOH.click(self.Phone1, **self.allow_permission)
        CommonOH.checkIfKeyExist(self.Phone1, 'image3')

        Step('步骤2.点击播放按钮')
        CommonOH.touchByKey(self.Phone1, 'image3')
        CommonOH.wait(self.Phone1, 4)
        Step('预期结果2.音乐正常播放且有声音')
        CommonOH.checkIfTextExist(self.Phone1, '00:00', expect=False)

        Step('步骤3.点击上一首切换按钮')
        CommonOH.touchByKey(self.Phone1, 'image2')
        CommonOH.wait(self.Phone1, 4)
        Step('预期结果3.正常切换到上一首音乐并流畅播放')
        CommonOH.checkIfTextExist(self.Phone1, 'demo.wav')
        CommonOH.checkIfTextExist(self.Phone1, '00:00', expect=False)

        Step('步骤4.点击下一首切换按钮')
        CommonOH.touchByKey(self.Phone1, 'image4')
        CommonOH.wait(self.Phone1, 4)
        Step('预期结果4.正常切换到下一首音乐并流畅播放')
        CommonOH.checkIfTextExist(self.Phone1, 'dynamic.wav')
        CommonOH.checkIfTextExist(self.Phone1, '00:00', expect=False)

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
